import Vue from 'vue'
import App from '../backend/App'   /*//app主框架*/
import router from '../backend/router' /* //路由*/
import iView from 'iview'
import vuex from  'vuex'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'iview/dist/styles/iview.css'
import '../../static/css/backend/main.css'

import store from '../../src/backend/store/index'

import commonFunc from '../../static/js/public'
import  '../../static/js/back-connect'

/*Vue.config.productionTip = false;*/
Vue.use(ElementUI);
Vue.use(iView);
Vue.use(vuex);
//前端登录拦截，路由拦截
router.beforeEach((to,from,next) => {
    console.log(to);
    if(to.path=='/'){
        if(commonFunc.getCookie('access_token')){
            next('/main');
        }else{
            next();
        }
    }else{
        if(to.meta.requireAuth){
            if(commonFunc.getCookie('access_token')){
                next();
            }else{
                next({path:'/'});
            }
        }else{
            next();
        }
        next();
    }
});
/* eslint-disable no-new */
new Vue({
    el: '#appbackend',
    router,
    store,
    components: { App },
    template: '<App/>'
});
